import { defineStore } from 'pinia'
import { ref } from 'vue'

// 用户模块
export const useUserStore = defineStore(
  'user-user',
  () => {
    const token = ref('')
    const setToken = (t) => {
      token.value = t
    }
    const removeToken = () => {
      token.value = ''
    }
    // 学号，用来做查询信息的关键字
    const studentId = ref('')
    const setStudentId = (t) => {
      studentId.value = t
    }
    // 注册时的用户id，用来作为报名信息的创建者id
    const userId = ref('')
    const setUserId = (t) => {
      userId.value = t
    }
    // 标志是否报名，默认为否
    const isSignUp = ref(false)
    const setIsSignUp = (t) => {
      isSignUp.value = t
    }

    const removeAll = () => {
      token.value = ''
      studentId.value = ''
      userId.value = ''
      isSignUp.value = ''
    }
    return {
      token,
      setToken,
      removeToken,

      studentId,
      setStudentId,

      userId,
      setUserId,

      isSignUp,
      setIsSignUp,

      removeAll
    }
  },
  {
    persist: true
  }
)